package com.dxy.app.utils;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

/**
  *Created by duxingyu on 2017/7/25.15:30
  *Email: 
  *Description:屏幕相关信息的工具类
  **/

public class ScreenUtils {

    public static int screenWidth;
    public static int screenHeight;
    public static int selfDpi;

    private ScreenUtils(Activity act){
        initialSomeParams(act);
    }

    private void initialSomeParams(Activity act){
        if(act==null){
            return;
        }
        WindowManager manager =act.getWindowManager();
        Display display =manager.getDefaultDisplay();
        DisplayMetrics metrics =new DisplayMetrics();
        display.getMetrics(metrics);
        selfDpi =metrics.densityDpi;

        screenWidth =metrics.widthPixels;
        screenHeight =metrics.heightPixels;
    }
    private static ScreenUtils screen;
    public static ScreenUtils getScreen(Activity act){
        if(screen==null){
            synchronized (ScreenUtils.class){
                if(screen ==null){
                    screen =new ScreenUtils(act);
                }
            }
        }
        return screen;
    }

    public static int getTranslateNumerial(int params){
        float f =selfDpi/312f;
        return (int) (params*f);
    }
    public static float getFloatTranslateNumer(float params){
        float f =selfDpi/312f;
        return params*f;
    }
}
